﻿package plugin.wing.controller
{
    import base.*;
    import plugin.component.view.*;
    import plugin.wing.ui.*;

    public class WingModelControl extends Object
    {
        private var mUI:WingUIControl;
        private var mCurLevel:int = 0;
        private var mHorseCfg:Object;
        private var mHorseLevelCfg:Object;
        public var mCurModel:RoleShow;
        public var mNextModel:RoleShow;
        private var mMaxHorseLevel:int = 0;

        public function WingModelControl(param1:WingUIControl)
        {
            var _loc_2:String = null;
            this.mHorseCfg = ConfigDictionary.data.wing;
            this.mHorseLevelCfg = ConfigDictionary.data.wingprop;
            this.mUI = param1;
            for (_loc_2 in this.mHorseCfg)
            {
                
                if (int(_loc_2) > this.mMaxHorseLevel)
                {
                    this.mMaxHorseLevel = int(_loc_2);
                }
            }
            this.reset();
            return;
        }// end function

        public function reset() : void
        {
            this.mCurLevel = this.ui.horseData.level;
            this.updateCurHorse(this.mCurLevel);
            return;
        }// end function

        private function updateCurHorse(param1:int) : void
        {
            var _loc_2:Object = null;
            var _loc_3:Object = null;
            var _loc_4:Boolean = false;
            this.ui.modelBox.mouseChildren = false;
            this.ui.modelBox.mouseEnabled = _loc_4;
            if (param1 == 0)
            {
                _loc_2 = null;
                _loc_3 = this.mHorseCfg[1];
            }
            else if (param1 == 15)
            {
                _loc_2 = this.mHorseCfg[this.mCurLevel];
                _loc_3 = this.mHorseCfg[this.mCurLevel];
            }
            else
            {
                _loc_2 = this.mHorseCfg[this.mCurLevel];
                _loc_3 = this.mHorseCfg[(this.mCurLevel + 1)];
            }
            if (this.mCurModel)
            {
                this.mCurModel.destroy();
                this.mCurModel = null;
            }
            if (!this.mCurModel && _loc_2)
            {
                this.mCurModel = new RoleShow(_loc_2.model, 4, null, _loc_2, null);
                this.mCurModel.x = 242;
                this.mCurModel.y = 342;
                this.ui.modelBox.addChild(this.mCurModel);
            }
            if (this.mNextModel)
            {
                this.mNextModel.destroy();
                this.mNextModel = null;
            }
            if (!this.mNextModel)
            {
                this.mNextModel = new RoleShow(_loc_3.model, 4, null, _loc_3, null);
                this.mNextModel.x = 577;
                this.mNextModel.y = 342;
                this.ui.modelBox.addChild(this.mNextModel);
            }
            if (param1 == 0)
            {
                this.ui.imgCurLevel.visible = false;
                this.ui.wingNameImg.visible = false;
                this.ui.wingNameImg2.url = "cs2_horse/1.png";
                this.ui.levelImg2.url = "cs2_horse/wingjie1.png";
                this.ui.wingNameImg2.filters = [FilterDefine.grayFilter];
                this.ui.levelImg2.filters = [FilterDefine.grayFilter];
            }
            else if (param1 < 15)
            {
                this.ui.imgCurLevel.visible = true;
                this.ui.wingNameImg.visible = true;
                this.ui.wingNameImg.url = "cs2_horse/" + param1 + ".png";
                this.ui.imgCurLevel.url = "cs2_horse/wingjie" + param1 + ".png";
                this.ui.wingNameImg2.url = "cs2_horse/" + (param1 + 1) + ".png";
                this.ui.levelImg2.url = "cs2_horse/wingjie" + (param1 + 1) + ".png";
                this.ui.wingNameImg2.filters = null;
                this.ui.levelImg2.filters = null;
            }
            else
            {
                this.ui.imgCurLevel.visible = true;
                this.ui.wingNameImg.visible = true;
                this.ui.wingNameImg.url = "cs2_horse/" + param1 + ".png";
                this.ui.imgCurLevel.url = "cs2_horse/wingjie" + param1 + ".png";
                this.ui.wingNameImg2.url = "cs2_horse/" + param1 + ".png";
                this.ui.levelImg2.url = "cs2_horse/wingjie" + param1 + ".png";
                this.ui.wingNameImg2.filters = null;
                this.ui.levelImg2.filters = null;
            }
            if (param1 < 15)
            {
                this.ui.btnItemUpgrade.disabled = false;
                this.ui.btnAutoUpgrade.disabled = false;
            }
            else
            {
                this.ui.btnItemUpgrade.disabled = true;
                this.ui.btnAutoUpgrade.disabled = true;
            }
            return;
        }// end function

        private function get ui() : WingUIControl
        {
            return this.mUI;
        }// end function

    }
}
